from selenium import webdriver
from selenium.webdriver.support.ui import  Select
driver = webdriver.Chrome()
driver.get('https://www.vmall.com/')
driver.implicitly_wait(10)

#进入华为官网
driver.find_element_by_css_selector('.shortcut  a[href*="consumer"]').click()

#进入华为应用市场
driver.find_element_by_css_selector('.s-sub ul li:nth-last-child(1)').click()
driver.find_element_by_css_selector('a[href^="http://appstore"]').click()

# Select1=Select(driver.find_element_by_css_selector('.s-sub ul li:nth-last-child(1)'))
# Select=Select1.select_by_visible_text('应用市场')

def checkhuawei():
    expected = '''智能手机|笔记本|平板|智能穿戴|智能家居|更多产品|软件应用|服务与支持'''

    size = driver.get_window_size()
    driver.set_window_size(1520, size['height'])

    ele = driver.find_elements_by_css_selector('.left-box ul li[class*="nav-list"]')
    ele2=[eles.text for eles in ele]
    # print(ele2)
    ctual = '|'.join(ele2)

    if ctual==expected:
        print(ctual)
    else:
        print('huawei page fail!!!')

def checkAPP():
    expected = '''首页|游戏|软件|专题|品牌专区|华为软件专区'''
    ele = driver.find_elements_by_css_selector('.lay-navi >div >ul >li')
    ele2=[eles.text for eles in ele]
    ctual = '|'.join(ele2)

    if ctual==expected:
        print(ctual)

    else:
        print('checkAPP is  fail!!!')

def checkVMALL():
    expected = '''平板电脑|笔记本电脑|笔记本配件'''
    #使鼠标悬停在笔记本$平板电脑那一栏
    from selenium.webdriver.common.action_chains import ActionChains
    ac =ActionChains(driver)
    ac.move_to_element(driver.find_element_by_css_selector('#zxnav_1')).perform()

    ele = driver.find_elements_by_css_selector('#zxnav_1 .subcate-item a span')
    ele2 = [eles.text for eles in ele]
    caual = '|'.join(ele2 )

    if caual == expected:
        print(caual)
    else:
        print("checkVMALL page fall !!!")


for handle in driver.window_handles:
    driver.switch_to.window(handle)

    if '消费者业务官网' in driver.title:
        checkhuawei()
    elif '华为应用市场' in driver.title:
        checkAPP()
    else:
        checkVMALL()
